/**
 * 
 */
var map;
var lastMarker=0;

var markersArray = [];
var currentPosition;

function initializeMap($container) {
  if (GBrowserIsCompatible()) {
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	
	
	map = new GMap2($container[0]);
	map.setCenter(new GLatLng(42.019776,-1.487832), 15);
	
	
  }
}

function centerAndMark(latitude,longitude)
{
	
	
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	baseIcon.iconSize = new GSize(21, 34);
	baseIcon.shadowSize = new GSize(22, 20);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld="+(++lastMarker)+"|00CC99|000000";
	map.setCenter(new GLatLng(latitude,longitude));
	var point = new GLatLng(latitude,longitude);
	markerOptions = { icon:letteredIcon };
	var marker = new GMarker(point,markerOptions);
	markersArray.push(marker);
	map.addOverlay(marker);
	
	
	map.setUIToDefault();
}
function setCurrentPosition(latitude,longitude)
{
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	baseIcon.iconSize = new GSize(12, 20);
	baseIcon.shadowSize = new GSize(22, 20);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
	map.setCenter(new GLatLng(latitude,longitude));
	var point = new GLatLng(latitude,longitude);
	markerOptions = { icon:letteredIcon };
	if (currentPosition)
	{
		map.removeOverlay(currentPosition);
	}
	currentPosition = new GMarker(point,markerOptions);
	
	map.addOverlay(currentPosition);
}

function clearMap()
{
	
  if (markersArray) {
    for (i=0;i<markersArray.length;i++) {
    	
    	map.removeOverlay(markersArray[i]);
    }
  }
  if (currentPosition)
	{
		map.removeOverlay(currentPosition);
	}
		
}